package br.com.ds3.model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;

@Entity(name = "GRUPO")
@SequenceGenerator(sequenceName = "SEQGRUPO", name = "SEQGRUPO", allocationSize=1, initialValue = 1)
public class Grupo extends GenericModel{
	
	@Id
	@Column(name = "IDGRUPO")
	@GeneratedValue(generator = "SEQGRUPO", strategy = GenerationType.SEQUENCE)	
	private Long id;
	
	@Column(name = "IDENTIFICACAO", length = 50, nullable = false)	
	private String identificacao;	
	
	@Column(name = "DESCONTO")
	private Double desconto;
	
	@ManyToMany( targetEntity=Usuario.class, cascade={CascadeType.PERSIST, CascadeType.MERGE} )
	@JoinTable( name="GRUPO_USUARIO",  
				joinColumns=@JoinColumn(name="IDGRUPO"),  
				inverseJoinColumns=@JoinColumn(name="IDUSUARIO") )  	
	private List<Usuario> usuarios;		
	
	@OneToMany(mappedBy = "grupo", targetEntity = Inscricao.class, fetch = FetchType.LAZY, cascade = CascadeType.ALL )
	private List<Inscricao> inscricoes;
	
	public Double getDesconto() {
		return desconto;
	}
	
	public void setDesconto(Double desconto) {
		this.desconto = desconto;
	}
	
	public List<Usuario> getUsuarios() {
		return usuarios;
	}
	
	public void setIndividuos(List<Usuario> usuarios) {
		this.usuarios = usuarios;
	}
	
	public List<Inscricao> getInscricoes() {
		return inscricoes;
	}
	
	public void setInscricoes(List<Inscricao> inscricoes) {
		this.inscricoes = inscricoes;
	}

	public String getIdentificacao() {
		return identificacao;
	}

	public void setIdentificacao(String identificacao) {
		this.identificacao = identificacao;
	}		
	
	public int getNumParticipantes() {
		return inscricoes.size();
	}

	@Override
	public Long getId() {
		return id;
	}

	@Override
	public void setId(Long id) {
		this.id = id;		
	}
	
	
}
